package com.koron.css2.newProjectCenter.callback;

import com.alibaba.fastjson.JSONObject;
import com.koron.css2.newProjectCenter.bean.PjInfoBean;
import com.koron.css2.newProjectCenter.service.PjInfoService;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.util.Constant;
import com.koron.util.HttpUtil;
import com.koron.util.secret.StaticInfo;
import org.apache.commons.lang3.StringUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.swan.bean.MessageBean;

/**
 * 施工勘察节点回调
 */
@Service(PjInfoService.SURVEY)
public class SurveyCallback implements IPjInfoNodeCallback{

    private static Logger logger = LoggerFactory.getLogger(SurveyCallback.class);

    @Override
    public MessageBean callback(SessionFactory factory, PjInfoBean pjInfoBean, UserInfoBean userInfo) {
        if (DZZW_COMPANY.equals(userInfo.getCurWaterCode()) && "14".equals(pjInfoBean.getSourceFlag())){
            try {
                JSONObject jsonObject = new JSONObject();
                // 设置状态为3-许可办结
                jsonObject.put("opStatus", "3");
                // 设置业务 id  pj_info_new的id
                jsonObject.put("gcid", pjInfoBean.getId());
                // 调用政务公共应用平台的业务状态修改接口
                String s = HttpUtil.sendPost(StaticInfo.interBusiApi + "/busiSyc/wxUpdateOpStatusByGcId", jsonObject.toJSONString());
                if (StringUtils.isBlank(s)) {
                    logger.error("办结状态信息返回为空！");
                    return MessageBean.create(Constant.MESSAGE_INT_FAIL, "办结状态推送失败！", Void.class);
                }
                net.sf.json.JSONObject responseData = com.koron.util.JsonUtils.jsonToPojo(s, net.sf.json.JSONObject.class);
                if (!"0".equals(responseData.getString("code"))) {
                    logger.error("儋州施工勘察审批推送办结状态至政务公共应用平台失败:" + responseData.getString("description"));
                    return MessageBean.create(Constant.MESSAGE_INT_FAIL, "施工勘察推送办结状态失败！", Void.class);
                }
            } catch (Exception e) {
                logger.error("儋州施工勘察审批推送办结状态至政务公共应用平台失败,原因：" + e, e);
                return MessageBean.create(Constant.MESSAGE_INT_FAIL, "施工勘察推送办结状态失败！", Void.class);
            }
        }
        return MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", Void.class);
    }
}
